package com.jing.ads.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;

import com.jing.ads.R;
import com.jing.ads.activity.ActivityInstall;

public class NotificationUtil {

	private static NotificationUtil notify = null;

	private Context context;

	private NotificationManager manager;

	private NotificationUtil(Context context) {
		this.context = context;
		manager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);
	}

	public static NotificationUtil getInstance(Context context) {
		if (notify == null) {
			notify = new NotificationUtil(context);
		}
		return notify;
	}

	public void showNotify(String title, String content, String pckName, boolean isInstall) {
		Notification notification = new Notification(R.drawable.float_sync, title,
				System.currentTimeMillis());
		// FLAG_AUTO_CANCEL 该通知能被状态栏的清除按钮给清除掉
		// FLAG_NO_CLEAR 该通知不能被状态栏的清除按钮给清除掉
		// FLAG_ONGOING_EVENT 通知放置在正在运行
		// FLAG_INSISTENT 是否一直进行，比如音乐一直播放，知道用户响应
		notification.flags |= Notification.FLAG_AUTO_CANCEL; // 将此通知放到通知栏的"Ongoing"即"正在运行"组中
//		notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在点击了通知栏中的"清除通知"后，此通知不清除，经常与FLAG_ONGOING_EVENT一起使用
		notification.flags |= Notification.FLAG_SHOW_LIGHTS;
		// DEFAULT_ALL 使用所有默认值，比如声音，震动，闪屏等等
		// DEFAULT_LIGHTS 使用默认闪光提示
		// DEFAULT_SOUNDS 使用默认提示声音
		// DEFAULT_VIBRATE 使用默认手机震动，需加上<uses-permission
		// android:name="android.permission.VIBRATE" />权限
		notification.defaults = Notification.DEFAULT_LIGHTS;
		// 叠加效果常量
		// notification.defaults=Notification.DEFAULT_LIGHTS|Notification.DEFAULT_SOUND;
		notification.ledARGB = Color.BLUE;
		notification.ledOnMS = 1000; // 闪光时间，毫秒
		Intent intent = new Intent(context,	ActivityInstall.class); 
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.putExtra("package_name", pckName);
		intent.putExtra("is_install", isInstall);
		int id = (int) (System.currentTimeMillis() % 10000);
		PendingIntent contentItent = PendingIntent.getActivity(context, id, intent, 0);
		notification.setLatestEventInfo(context, title, content, contentItent);
		manager.notify(id, notification);
	}
}
